<template>
  <div class="user-management-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="4">
        <!-- <el-form-item>
          <el-button type="primary" @click="handleDownload">
            导出 Excel
          </el-button>
        </el-form-item> -->
        <!-- <el-button icon="el-icon-plus" type="primary" @click="handleEdit">
          添加
        </el-button> -->
        <!-- <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
          批量删除
        </el-button> -->
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="20">
        <el-form :inline="true" :model="queryForm" @submit.prevent>
          <el-form-item style="padding-right: 10px">
            <el-select v-model="queryForm.status" placeholder="是否开票">
              <el-option value="">全部</el-option>
              <el-option
                v-for="(type, i) in alias.status_alias"
                :key="i"
                clearable="true"
                :label="type"
                :value="i"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.metting_name"
              clearable
              placeholder="请输入会议标题"
              style="padding-right: 10px"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.order_no"
              clearable
              placeholder="请输入订单号"
              style="padding-right: 10px"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.info"
              clearable
              placeholder="抬头\税号\接收人\接收电话"
              style="padding-right: 10px"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <!-- <el-table-column align="center" show-overflow-tooltip type="selection" /> -->
      <!-- <el-table-column
        align="center"
        label="ID"
        prop="id"
        show-overflow-tooltip
      /> -->
      <el-table-column
        align="center"
        label="会议标题"
        prop="metting_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="订单号"
        prop="order_no"
        show-overflow-tooltip
      />
      <!-- <el-table-column
        align="center"
        label="客户名称"
        prop="name"
        show-overflow-tooltip
      /> -->
      <el-table-column
        align="center"
        label="类型"
        show-overflow-tooltip
        width="80"
      >
        <template #default="{ row }">
          <el-tag>
            {{ row.type_alias }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="开票状态"
        prop="status"
        show-overflow-tooltip
        width="80"
      >
        <template #default="{ row }">
          <!-- <el-tooltip
            :content="row.status === 2 ? '点击已开票' : '点击未开票'"
            :enterable="false"
            placement="top"
          > -->
          <el-switch
            v-model="row.status"
            :active-value="1"
            disabled
            :inactive-value="2"
          />
          <!-- </el-tooltip> -->
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="抬头"
        prop="header"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="税号"
        prop="tax_no"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="邮箱"
        prop="email"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="注册地址"
        prop="register_address"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="注册电话"
        prop="register_mobile"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="开户行"
        prop="bank_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="账号"
        prop="bank_account"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="邮寄地址"
        prop="address"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="接收人"
        prop="receive"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="接收电话"
        prop="receive_mobile"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="创建时间"
        prop="create_time"
        show-overflow-tooltip
      />

      <!-- <el-table-column
        align="center"
        label="操作"
        show-overflow-tooltip
        width="150"
      >
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">编辑</el-button>
          <el-button type="text" @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column> -->
      <template #empty>
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <edit ref="editRef" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { useRouter } from 'vue-router'
  import {
    defineComponent,
    onMounted,
    reactive,
    toRefs,
    getCurrentInstance,
  } from 'vue'
  import { getList, doEdit } from '@/api/ordeInvoice'
  export default defineComponent({
    name: 'OrderInvoiceManagement',
    setup() {
      const { proxy } = getCurrentInstance()
      const router = useRouter()
      const state = reactive({
        editRef: null,
        list: [],
        alias: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          metting_name: '',
          status: '',
        },
      })

      const setSelectRows = (val) => {
        state.selectRows = val
      }
      const handleEdit = (row) => {
        if (row.id) {
          router.push({ path: '/metting/edit', query: { id: row.id } })
        } else {
          router.push('/metting/create')
        }
      }
      const handleSizeChange = (val) => {
        state.queryForm.pageSize = val
        fetchData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.pageNo = val
        fetchData()
      }
      const queryData = () => {
        state.queryForm.pageNo = 1
        fetchData()
      }
      const fetchData = async () => {
        state.listLoading = true
        const {
          data: { list, total, alias },
        } = await getList(state.queryForm)
        state.list = list
        state.total = total
        state.alias = alias
        state.listLoading = false
        console.log(state.alias)
      }
      const changeStatus = async (id) => {
        const { msg } = await doEdit({ id: id })
        proxy.$baseMessage(msg, 'success', 'vab-hey-message-success')
        fetchData()
      }
      onMounted(() => {
        fetchData()
      })

      return {
        ...toRefs(state),
        setSelectRows,
        handleEdit,
        handleSizeChange,
        handleCurrentChange,
        queryData,
        fetchData,
        changeStatus,
      }
    },
    methods: {
      // changeStatus: async function (id) {
      //   // const { proxy } = getCurrentInstance()
      //   const { msg } = await doEdit({ id: id })
      //   getCurrentInstance().$baseMessage(
      //     msg,
      //     'success',
      //     'vab-hey-message-success'
      //   )
      // },
    },
  })
</script>
